<?php

// ------------------------------------------------------------------------
// |@Author       : Jarmin <edshop@qq.com>
// |@----------------------------------------------------------------------
// |@Date         : 2025-05-06 22:16:38
// |@----------------------------------------------------------------------
// |@LastEditTime : 2025-05-11 01:44:14
// |@----------------------------------------------------------------------
// |@LastEditors  : Jarmin <topextend@qq.com>
// |@----------------------------------------------------------------------
// |@Description  :
// |@----------------------------------------------------------------------
// |@FilePath     : SystemApiVersions.php
// |@----------------------------------------------------------------------
// |@Copyright (c) 2025 http://www.ladmin.cn All Rights Reserved.
// ------------------------------------------------------------------------
declare (strict_types=1);

namespace think\admin\model;

use think\admin\Model;

/**
 * 系统接口版本模型
 * Class SystemApiVersions
 * @package think\admin\model
 */
class SystemApiVersions extends Model
{
    // 设置字段信息
    protected $schema = [
        'id'                => 'int',
        'version'           => 'string',
        'status'            => 'int',
        'is_default'        => 'int',
        'release_at'        => 'date',
        'expire_at'         => 'date',
        'end_of_life'       => 'date',
        'warning_days'      => 'int',
        'force_upgrade_days' => 'int',
        'upgrade_guide_url' => 'string',
        'description'       => 'string',
        'created_at'        => 'datetime',
        'updated_at'        => 'datetime',
    ];

    // 自动时间戳
    protected $autoWriteTimestamp = true;

    // 时间字段格式化
    protected $type = [
        'release_at'  => 'date',
        'expire_at'   => 'date',
        'end_of_life' => 'date',
    ];

    // 获取器
    public function getStatusTextAttr($value, $data)
    {
        $status = [0 => '禁用', 1 => '启用'];
        return $status[$data['status']] ?? '未知';
    }

    public function getIsDefaultTextAttr($value, $data)
    {
        $status = [0 => '否', 1 => '是'];
        return $status[$data['is_default']] ?? '未知';
    }

    // 修改器
    public function setVersionAttr($value)
    {
        return strtolower($value);
    }
}
